﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DiGraph;


namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var di_graph = new DirectedGraph();
            di_graph.AddVertex("v1");
            di_graph.AddVertex("v2");
            di_graph.AddVertex("v3");
            di_graph.AddVertex("v4");
            di_graph.AddVertex("v5");
            di_graph.AddVertex("v6");
            di_graph.AddVertex("v7");
            di_graph.AddEdge("v1", "v2", 5);
            di_graph.AddEdge("v1", "v3", 3);
            di_graph.AddEdge("v1", "v5", 7);
            di_graph.AddEdge("v2", "v4", 6);
            di_graph.AddEdge("v2", "v5", 3);
            di_graph.AddEdge("v3", "v5", 8);
            di_graph.AddEdge("v3", "v6", 3);
            di_graph.AddEdge("v4", "v7", 9);
            di_graph.AddEdge("v5", "v7", 8);
            di_graph.AddEdge("v6", "v7", 7);

            Console.WriteLine("The Graph:");
            Console.WriteLine(di_graph);
            Console.WriteLine("========================================");

            Console.WriteLine("The Graph in DOT lang:");
            Console.WriteLine(di_graph.ToDotFormat());
            Console.WriteLine("========================================");

            //DFS
            var dfs=di_graph.DepthFirstSearch("v1");
            StringBuilder str_builder = new StringBuilder();
            foreach (var node in dfs)
                str_builder.AppendFormat("{0},",node);
            str_builder.Remove(str_builder.Length - 1, 1);
            Console.WriteLine("DFS: {0}", str_builder.ToString());
            Console.WriteLine("========================================");

            //BFS
            var bfs = di_graph.BreathFirstSearch("v1");
            str_builder = new StringBuilder();
            foreach (var node in bfs)
                str_builder.AppendFormat("{0},", node);
            str_builder.Remove(str_builder.Length - 1, 1);
            Console.WriteLine("BFS: {0}", str_builder.ToString());
            Console.WriteLine("========================================");

            //Topoligical Order
            var topological = di_graph.TopologicalOrder();
            str_builder = new StringBuilder();
            foreach (var node in topological)
                str_builder.AppendFormat("{0},", node);
            str_builder.Remove(str_builder.Length - 1, 1);
            Console.WriteLine("Topological Order: {0}", str_builder.ToString());
            Console.WriteLine("========================================");

            //Critical path
            var critical_path = di_graph.GetCriticalPath();
            str_builder = new StringBuilder();
            foreach (var node in critical_path)
                str_builder.AppendFormat("{0},", node);
            str_builder.Remove(str_builder.Length - 1, 1);
            Console.WriteLine("Critical path: {0}", str_builder.ToString());
            Console.WriteLine("Critical path length: {0}", di_graph.CriticalPathLength());
            Console.WriteLine("========================================");

            //Manuplating Vertices and Edges
            di_graph.UpdateVertex("v1", 32);
            di_graph.UpdateEdge("v1", "v2", 12);
            di_graph.ZeroEdge("v1", "v2");
            di_graph.RemoveEdge("v1", "v2");
            di_graph.RemoveVertex("v7");
          
            Console.WriteLine("Press Enter to Continue...");
            Console.ReadLine();
        }
    }
}
